#include "kernel/types.h"
#include "user/user.h"

int main(int argc, char* argv[]) {
    //read and write with standard input/output (0/1)
    int n;
    char buf[64];

    fprintf(2, "please input:\n");
    //read and write (like cat)
    while((n = read(0, buf, sizeof(buf))) > 0) {
        //read: read buffer size (fd, the buffer copy to, read buffer size)
        //return 0 when read at the end

        n = read(0, buf, sizeof(buf));
        if (n == 0) {   //can not exist, why?😓 (cause standard input?)
            printf("end of read\n");
            break;
        }
        else if (n < 0) {
            fprintf(2, "read error\n");
            exit(1);
        }

        //write: write buffer size (fd, the buffer write from, write buffer size)
        if (write(1, buf, n) != n) {
            fprintf(2, "write error\n");
            exit(1);
        }
    }

    exit(0);
}